package com.xmb.wechat.old;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.ActivityUtils;
import com.squareup.picasso.Picasso;
import com.xmb.wechat.R;
import com.xmb.wechat.R2;
import com.xmb.wechat.entity.WechatAppInfoBean;
import com.xmb.wechat.picasso.PicassoRoundByPercentTransform;
import com.xmb.wechat.view.wechat.money.WechatFundChangeActivity;
import com.xmb.wechat.view.wechat.setting.WechatMyInfoActivity;
import com.xmb.wechat.view.wechat.setting.WechatSettingActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 我
 */
public class MineFragment extends Fragment {

    @BindView(R2.id.iv_touxiang)
    ImageView      ivTouxiang;
    @BindView(R2.id.tv_name)
    TextView       tvName;
    @BindView(R2.id.tv_id)
    TextView       tvId;
    @BindView(R2.id.iv_arrow)
    ImageView      ivArrow;
    @BindView(R2.id.btn_my_info)
    RelativeLayout btnMyInfo;
    @BindView(R2.id.iv_zhifu)
    ImageView      ivZhifu;
    @BindView(R2.id.btn_pay)
    RelativeLayout btnPay;
    @BindView(R2.id.iv_shouchang)
    ImageView      ivShouchang;
    @BindView(R2.id.iv_xiangche)
    ImageView      ivXiangche;
    @BindView(R2.id.iv_kabao)
    ImageView      ivKabao;
    @BindView(R2.id.iv_biaoqin)
    ImageView      ivBiaoqin;
    @BindView(R2.id.iv_shezhi)
    ImageView      ivShezhi;
    @BindView(R2.id.btn_setting)
    RelativeLayout btnSetting;
    @BindView(R2.id.view_cards)
    View           viewCards;
    @BindView(R2.id.re_cards)
    RelativeLayout reCards;
    Unbinder unbinder;


    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.wechat_fragment_me, container, false);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        viewCards.setVisibility(View.GONE);
        reCards.setVisibility(View.GONE);
    }

    @Override
    public void onResume() {
        super.onResume();
        update();
    }

    private void update() {
        WechatAppInfoBean vo = WechatAppInfoBean.getWechat(getContext());
        if (vo != null) {
            Picasso.get().load("file:" + vo.getAvatar()).error(R.drawable.ic_wx_default_avatar).transform(new PicassoRoundByPercentTransform(12)).into(ivTouxiang);
            tvName.setText(vo.getName());
            tvId.setText("微信号：" + vo.getWechat_id());
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R2.id.btn_my_info, R2.id.btn_pay, R2.id.btn_setting})
    public void onViewClicked(View view) {
        int i = view.getId();//设置个人信息：
        if (i == R.id.btn_my_info) {
            ActivityUtils.startActivity(WechatMyInfoActivity.class);
            //支付：
        } else if (i == R.id.btn_pay) {
            ActivityUtils.startActivity(WechatFundChangeActivity.class);
            //设置：
        } else if (i == R.id.btn_setting) {
            ActivityUtils.startActivity(WechatSettingActivity.class);
        }
    }
}
